package demo.day04

// Kotlin with 函数
fun main() {
    var result: Any? = null
    // 具名操作
    val str = "Kikiki"
    result = with(str, ::isLong)
    println(result)
    result = with(result, ::showText)
    println(result)
    result = with(result, ::mapText)
    println(result)

    // 匿名操作
    with(with(with(str) {
        length
    }) {
        "你的字符串长度是${this}"
    }) {
        println(this)
    }

}

private fun isLong(str: String) = if (str.length > 5) true else false

private fun showText(isLong: Boolean) = if (isLong) "字符串合格" else "字符串不合格"

private fun mapText(getShow: String) = "[$getShow]"